package com.cjjd.c.feature.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationClientOption.AMapLocationMode;
import com.amap.api.location.AMapLocationListener;
import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseFragment;
import com.cjjd.c.bean.AdHotelBean;
import com.cjjd.c.bean.CheckoutItemBean;
import com.cjjd.c.bean.CityAdWrapperBean;
import com.cjjd.c.bean.HotelListItemBean;
import com.cjjd.c.bean.HotelQrCodeInfoBean;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.ListResult;
import com.cjjd.c.bean.NearbyHotelWrapperBean;
import com.cjjd.c.bean.ScanBean;
import com.cjjd.c.feature.LoaclImageLoader;
import com.cjjd.c.feature.WebviewActivity;
import com.cjjd.c.feature.dialog.Text2Dialog;
import com.cjjd.c.feature.home.call.CallActivity;
import com.cjjd.c.feature.home.call.CallFragment;
import com.cjjd.c.feature.home.checkout.CheckOutListActivity;
import com.cjjd.c.feature.home.chekin.checklist_detail.CheckinListActivity;
import com.cjjd.c.feature.home.ewm.ZingActivity;
import com.cjjd.c.feature.home.hoteldevice.HomeHotelDeviceActivity;
import com.cjjd.c.feature.home.scan.ScanInputActivity;
import com.cjjd.c.feature.home.subservice.SubscribeServiceFragment;
import com.cjjd.c.feature.mine.login.LoginActivity;
import com.cjjd.c.feature.mine.zxing.SecondActivity;
import com.cjjd.c.http.CallbackImpl;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.CheckPermissionUtils;
import com.cjjd.c.utils.DialogUtil;
import com.cjjd.c.utils.FragmentUtil;
import com.cjjd.c.utils.LogUtil;
import com.cjjd.c.utils.SharePrefUtil;
import com.cjjd.c.utils.ToastUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.zaaach.citypicker.CityPickerActivity;
import com.zaaach.citypicker.utils.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static android.app.Activity.RESULT_OK;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/9.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class MainFragment extends BaseFragment implements OnBannerListener {
    @Bind(R.id.tv_select_location)
    TextView tvSelectLocation;
    @Bind(R.id.tv_hotel_title)
    TextView tvHotelTitle;
    @Bind(R.id.tv_blrz)
    TextView tvBlrz;
    @Bind(R.id.banner)
    Banner banner;


    private CityAdWrapperBean.CityAdBean citiAdBean;
    private NearbyHotelWrapperBean.NearbyHotelBean nearbyHotelBean;

    // 已经入住酒店列表
    private List<HotelListItemBean> hotelList = new ArrayList<>();

    // 首页广告
    public List<String> images = new ArrayList<>();
    // 首页广告点击地址
    public List<String> imagesClickUrl = new ArrayList<>();

    // 当前城市名
    private String cityName;

    // 首页title显示的已经入住的酒店（定位的不算）
    private String hotelName;
    //首页title显示的酒店 UUID
    private String hotelUUID;


    private static final int CheckOut = 0x00000001;
    private static final int HotelDeivce = 0x00000002;
    private static final int HotelShoping = 0x00000003;
    private static final int HotelEating = 0x00000004;
    private static final int HotelCall = 0x00000005;
    private static final int HotelReceipt = 0x00000006;
    private static final int TittleClick = 0x00000007;
    private static final int HotelEWM = 0x00000008;


    // 退房订单列表信息
    private List<CheckoutItemBean> checkoutItemBeanList;

    @Override
    public int getContentView() {
        return R.layout.fragment_main;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);

        checkoutItemBeanList = new ArrayList<CheckoutItemBean>();

        initView();
        return rootView;
    }


    private void initView() {


        if (!SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false) ||
                (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false && SharePrefUtil.getBoolean(mContext, ShareKeys.canLocation, true)))
                ) {
            initLoaction();
        }
//        banner.setImageLoader(new LoaclImageLoader())
//                .setImages(images)
//                .setOnBannerListener(this)
//                .start();


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        //mLocationClient.startLocation();

        LogUtil.e("xyd", "onresume");
        if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)
                && TextUtils.isEmpty(SharePrefUtil.getString(mContext, ShareKeys.HomeHotelUuid, ""))) {
            getHotelList();
        } else if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)
                && !TextUtils.isEmpty(SharePrefUtil.getString(mContext, ShareKeys.HomeHotelUuid, ""))) {
            tvHotelTitle.setText(SharePrefUtil.getString(mContext, ShareKeys.HomeTittleName, ""));
            getHotelBanner(SharePrefUtil.getString(mContext, ShareKeys.HomeHotelUuid, ""));
        } else {
            if (!TextUtils.isEmpty(cityName)) {
                getAdvertByCity();
            }
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            LogUtil.e("xyd", "onHideChanged not hiddlen");
            if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)
                    && !TextUtils.isEmpty(SharePrefUtil.getString(mContext, ShareKeys.HomeHotelUuid, ""))) {
                tvHotelTitle.setText(SharePrefUtil.getString(mContext, ShareKeys.HomeTittleName, ""));
                getHotelBanner(SharePrefUtil.getString(mContext, ShareKeys.HomeHotelUuid, ""));
            }
        }
    }

    /**
     * 获取已入住酒店列表
     */
    private void getHotelList() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        //h1.put("nowPage", 0 + "");
        //h1.put("pageShow", 30 + "");

        Call<HttpResult<ListResult<HotelListItemBean>>> call = service.getHotelList(JsonUtils.convertParam("getHotelList", h1));
        call.enqueue(new CallbackImpl<ListResult<HotelListItemBean>>() {
            @Override
            public void responseSuccess(Call<HttpResult<ListResult<HotelListItemBean>>> call, Response<HttpResult<ListResult<HotelListItemBean>>> response) {
                if (response.body().getData().dataList != null) {
                    if (hotelList.size() > 0) hotelList.clear();
                    hotelList.addAll(response.body().getData().dataList);

                    if (hotelList.size() > 0) {
                        hotelName = hotelList.get(0).hotelName;
                        //dada add
                        hotelUUID=hotelList.get(0).hotelUuid;
                        SharePrefUtil.saveString(mContext, ShareKeys.HomeHotelUuid,hotelUUID);
                        if (tvHotelTitle != null) {
                            tvHotelTitle.setText(hotelName);
                            // 有入住信息的 title ，不允许定位。
                            SharePrefUtil.saveBoolean(mContext, ShareKeys.canLocation, false);
                        }
                        getHotelBanner(hotelList.get(0).hotelUuid);
                    } else {
                        // 没有入住酒店， 就去获取定位的城市的 ad
                        SharePrefUtil.saveString(mContext, ShareKeys.HomeTittleName, "");
                        SharePrefUtil.saveString(mContext, ShareKeys.HomeHotelUuid, "");
                        hotelName = "";
                        //dada add
                        hotelUUID="";
                        if (!TextUtils.isEmpty(cityName)) getAdvertByCity();
                    }

                }
            }
        });

    }

    /**
     * 获取酒店广告
     */
    private void getHotelBanner(String hotelUuid) {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("hotelId", hotelUuid);

        Call<HttpResult<ListResult<AdHotelBean>>> call = service.getHotelBanner(JsonUtils.convertParam("getHotelBanner", h1));
        call.enqueue(new CallbackImpl<ListResult<AdHotelBean>>() {
            @Override
            public void responseSuccess(Call<HttpResult<ListResult<AdHotelBean>>> call, Response<HttpResult<ListResult<AdHotelBean>>> response) {
                List<AdHotelBean> adHotelBeanList = response.body().getData().dataList;
                if (adHotelBeanList != null) {
                    if (images.size() > 0) {
                        images.clear();
                        imagesClickUrl.clear();
                    }
                    for (int i = 0; i < adHotelBeanList.size(); i++) {
                        images.add(adHotelBeanList.get(i).imageUrl);
                        imagesClickUrl.add(adHotelBeanList.get(i).url);
                    }
                    try {
                        banner.setImageLoader(new LoaclImageLoader())
                                .setImages(images)
                                .setOnBannerListener(MainFragment.this)
                                .setOnBannerListener(new OnBannerListener() {
                                    @Override
                                    public void OnBannerClick(int position) {
                                        Intent webIntent = new Intent(mContext, WebviewActivity.class);
                                        webIntent.putExtra("weburl", imagesClickUrl.get(position));
                                        startActivity(webIntent);
                                    }
                                })
                                .start();
                    } catch (Exception e) {
                    }

                }
            }
        });
    }

    /**
     * 根据城市获取广告图
     */
    private void getAdvertByCity() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("city", cityName);

        Call<HttpResult<CityAdWrapperBean>> call = service.getAdvertByCity(JsonUtils.convertParam("getAdvertByCity", h1));
        call.enqueue(new CallbackImpl<CityAdWrapperBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<CityAdWrapperBean>> call, Response<HttpResult<CityAdWrapperBean>> response) {
                citiAdBean = response.body().getData().cityAd;
                if (citiAdBean != null) {
                    if (images.size() > 0) {
                        images.clear();
                        imagesClickUrl.clear();
                    }
                    images.addAll(citiAdBean.imageUrlList);
                    //images.addAll(citiAdBean);

                    if (banner != null)
                        banner.setImageLoader(new LoaclImageLoader())
                                .setImages(images)
                                .setOnBannerListener(MainFragment.this)
                                .start();
                }
            }
        });
    }


    //<editor-fold desc="自动定位">
    private AMapLocationClient mLocationClient;


    private void initLoaction() {
        mLocationClient = new AMapLocationClient(mContext);
        AMapLocationClientOption option = new AMapLocationClientOption();
        // 默认采用连续定位模式, 设置定位间隔,单位毫秒,默认为2000ms，最低1000ms。
        //option.setInterval(3000);
        option.setLocationMode(AMapLocationMode.Hight_Accuracy);
        // 如果您需要使用单次定位 true, 该方法默认为false。
        option.setOnceLocation(true);
        mLocationClient.setLocationOption(option);
        mLocationClient.setLocationListener(new AMapLocationListener() {
            public void onLocationChanged(AMapLocation aMapLocation) {
                if (aMapLocation != null) {
                    Log.e("xyd", "ErrorCode = " + aMapLocation.getErrorCode());
                    Log.e("xyd", "LocationDetail = " + aMapLocation.getLocationDetail());
                    if (aMapLocation.getErrorCode() == 0) {

                        double latitude = aMapLocation.getLatitude();    // 纬度
                        double longitude = aMapLocation.getLongitude();  // 经度
                        String city = aMapLocation.getCity();
                        String district = aMapLocation.getDistrict();
                        String location = StringUtils.extractLocation(city, district);
                        Log.e("xyd", "city = " + city + "; district = " + district + "; location = " + location);
                        Log.e("xyd", "district = " + aMapLocation.getDistrict());
                        Log.e("xyd", "Floor = " + aMapLocation.getFloor());
                        Log.e("xyd", "StateLites = " + aMapLocation.getSatellites());
                        Log.e("xyd", "Accuracy = " + aMapLocation.getAccuracy());
                        Log.e("xyd", "Street = " + aMapLocation.getStreet());

                        cityName = city;
                        tvSelectLocation.setText(city);
                        getAdvertByCity();

                        if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false) && TextUtils.isEmpty(hotelName)) {
                            // 登录后才会刷新
                            getNearbyHotel(latitude, longitude);
                        } else {

                        }
                        // mContext.mCityAdapter.updateLocateState(888, location);
                    } else {
                        //mContext.mCityAdapter.updateLocateState(666, (String) null);
                    }
                }

            }
        });
        mLocationClient.startLocation();
    }

    /**
     * 根据经纬度获取酒店
     *
     * @param latitude  纬度
     * @param longitude 经度
     */
    private void getNearbyHotel(double latitude, double longitude) {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("latitude", latitude + "");
        h1.put("longitude", longitude + "");

        Call<HttpResult<NearbyHotelWrapperBean>> call = service.getNearbyHotel(JsonUtils.convertParam("getNearbyHotel", h1));
        call.enqueue(new CallbackImpl<NearbyHotelWrapperBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<NearbyHotelWrapperBean>> call, Response<HttpResult<NearbyHotelWrapperBean>> response) {
                if (response.body().getData() != null && response.body().getData().hotel != null) {
                    nearbyHotelBean = response.body().getData().hotel;
                    if (nearbyHotelBean != null && TextUtils.isEmpty(hotelName)) {
                        tvHotelTitle.setText(nearbyHotelBean.hotelName);
                    }
                }
            }
        });

    }

    //</editor-fold>


    private static final int REQUEST_CODE_PICK_CITY = 0x00000001;

    @OnClick({R.id.tv_hotel_title, R.id.tv_select_location, R.id.tv_blrz, R.id.tv_checkout,
            R.id.tv_hotel_device,
            R.id.tv_sub_service, R.id.iv_scan, R.id.tv_call, R.id.tv_shop, R.id.tv_dcwm,
            R.id.tv_more
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_hotel_title:
                if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)) {
                    //dada add
                    checkHaveOrder(TittleClick);
                } else {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.tv_select_location:
                startActivityForResult(new Intent(mContext, CityPickerActivity.class),
                        REQUEST_CODE_PICK_CITY);
                break;
            case R.id.tv_blrz:

                if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)) {
                    Intent checkinIntent = new Intent(mContext, CheckinListActivity.class);
                    mContext.startActivity(checkinIntent);
                } else {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    startActivity(intent);
                }
                break;

            case R.id.tv_checkout:
                if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)) {
                    checkHaveOrder(CheckOut);
                } else {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.tv_hotel_device:
                checkHaveOrder(HotelDeivce);
                break;
            case R.id.tv_sub_service:
                ToastUtil.showToast("即将上线，敬请期待");

//                FragmentUtil.replaceWithAddToBack(mContext, new SubscribeServiceFragment(), R.id.activity_body);


                //FragmentUtil.replaceWithAddToBack(mContext, new BillAdvanceFragment(), R.id.activity_body);
                //checkHaveOrder(HotelReceipt);
                break;
            case R.id.iv_scan:
                if (SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)) {
                    LogUtil.e("xyd", "扫一扫");
                    checkCanScan();

                } else {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.tv_call:
                checkHaveOrder(HotelCall);

                break;

            case R.id.tv_shop:
                checkHaveOrder(HotelShoping);

                break;
            case R.id.tv_dcwm:
//                FragmentUtil.replaceWithAddToBack(mContext, new ShopFragment(), R.id.activity_body);
                checkHaveOrder(HotelEating);

                break;

            case R.id.tv_more:
//                addTestData();
                checkHaveOrder(HotelEWM);
                break;
        }
    }

    private void addTestData() {
        Call<HttpResult<Object>> call = service.addTestData("15611552330", "2");
        call.enqueue(new Callback<HttpResult<Object>>() {
            @Override
            public void onResponse(Call<HttpResult<Object>> call, Response<HttpResult<Object>> response) {

            }

            @Override
            public void onFailure(Call<HttpResult<Object>> call, Throwable t) {

            }
        });
    }

    /**
     * 检测title是否可以点击
     * 如果有订单存在，才可以
     */
    private void checkTittleCanClick() {


    }

    /**
     * 扫码支付需要用户有 待退房  状态的订单，才能使用
     */
    private void checkCanScan() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));

        Call<HttpResult<ListResult<CheckoutItemBean>>> call = service.getCustomerChekOutOrderList(JsonUtils.convertParam("getCustomerChekOutOrderList", h1));
        call.enqueue(new CallbackImpl<ListResult<CheckoutItemBean>>() {
            @Override
            public void responseSuccess(Call<HttpResult<ListResult<CheckoutItemBean>>> call, Response<HttpResult<ListResult<CheckoutItemBean>>> response) {
                if (checkoutItemBeanList.size() > 0) {
                    checkoutItemBeanList.clear();
                }
                checkoutItemBeanList.addAll(response.body().getData().dataList);

                boolean canScan = false;
                for (CheckoutItemBean bean : checkoutItemBeanList) {
                    if ("3".equals(bean.state)) {
                        canScan = true;
                        break;
                    }
                }

                // 退房订单中有  待退房  状态的信息。
                if (canScan) {
                    initPermission();
                } else {
                    ToastUtil.showToast("退房订单中没有【待退房】订单");
                }
            }
        });

    }

    /**
     * 判断是否可点击，(条件是否有订单)， 可点击，正常流程。 不可点击，弹提示框。
     * 提示框： 确定- 》 去入住订单页
     * 取消- 》 dismiss
     * <p>
     * 如果是title ，
     *
     * @param checktype
     */
    private void checkHaveOrder(final int checktype) {
        if (!SharePrefUtil.getBoolean(mContext, ShareKeys.isLogin, false)) {
            Intent intent = new Intent(mContext, LoginActivity.class);
            startActivity(intent);
            return;
        }

        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        //h1.put("nowPage", 0 + "");
        //h1.put("pageShow", 30 + "");

        Call<HttpResult<ListResult<HotelListItemBean>>> call = service.getHotelList(JsonUtils.convertParam("getHotelList", h1));
        call.enqueue(new CallbackImpl<ListResult<HotelListItemBean>>() {
            @Override
            public void responseSuccess(Call<HttpResult<ListResult<HotelListItemBean>>> call, Response<HttpResult<ListResult<HotelListItemBean>>> response) {

                if (response.body() != null && response.body().getData() != null && response.body().getData().wm != null) {
                    int totalNum = response.body().getData().wm.totalNum;
                    if (totalNum > 0) {
                        switch (checktype) {
                            case CheckOut:
                                Intent checkoutIntent = new Intent(mContext, CheckOutListActivity.class);
                                startActivity(checkoutIntent);
                                break;
                            case HotelDeivce:
//                                FragmentUtil.replaceWithAddToBack(mContext, new HotelDeviceFragment(), R.id.activity_body);
                                HomeHotelDeviceActivity.lauch(mContext);
                                break;
                            case HotelReceipt:
                                //ToastUtil.showToast("功能暂未开通");
                                break;
                            case HotelShoping:
                                ToastUtil.showToast("酒店商城暂未上线");
                                break;
                            case HotelEating:
                                ToastUtil.showToast("暂不提供线上点餐/外卖");
                                break;
                            case HotelCall:
//                                FragmentUtil.replaceWithAddToBack(mContext, new CallFragment(), R.id.activity_body);
                                CallActivity.lauch(mContext);
                                break;
                            case TittleClick:
                                FragmentUtil.replaceWithAddToBack(mContext, new SelectHotelFragment(), R.id.activity_body);
                                break;
                            case HotelEWM:
                                //二维码
                                ZingActivity.lauch(mContext);
                                break;
                        }

                    } else {
                        // 无入住订单
                        SharePrefUtil.saveString(mContext, ShareKeys.HomeTittleName, "");
                        SharePrefUtil.saveString(mContext, ShareKeys.HomeHotelUuid, "");

                        new Text2Dialog(mContext, "请办先办理入住哦", new Text2Dialog.OnCloseListener() {
                            @Override
                            public void OnClick() {
                                Intent checkinIntent = new Intent(mContext, CheckinListActivity.class);
                                mContext.startActivity(checkinIntent);
                            }

                            @Override
                            public void Onclose() {

                            }
                        }).show();
                    }


                }

            }
        });

    }

    private static int REQUEST_CODE = 0x00000001;

    /**
     * 初始化权限事件
     */
    private void initPermission() {


        //检查权限
        String[] permissions = CheckPermissionUtils.checkPermission(mContext);
        if (permissions.length == 0) {
            //权限都申请了
            //是否登录

            Intent intent = new Intent(mContext, SecondActivity.class);
            startActivityForResult(intent, REQUEST_CODE);
//            Intent intent = new Intent(mContext, CaptureActivity.class);
//            startActivityForResult(intent, REQUEST_CODE);

        } else {
            //申请权限
            ActivityCompat.requestPermissions(mContext, permissions, 100);
        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK) {
            if (data != null) {
                String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY);
                LogUtil.e("xyd", "当前选择的城市是： " + city);
                if (!TextUtils.isEmpty(city)) {
                    cityName = city;
                    tvSelectLocation.setText(city);
                    getAdvertByCity();
                }

            }
        }
        if (requestCode == REQUEST_CODE) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    String result = bundle.getString(CodeUtils.RESULT_STRING);

                    // weixin://wxpay/bizpayurl?pr=F1M5xiZ
                    // wxp://f2f17digx1VP-TX6uB76jIKY4e8i7uE0yV1l
                    // HTTPS://QR.ALIPAY.COM/FKX032577YXU87CPB4RBD4
                    // {"costType":"的散发的是的的","hotel":"731442f18425499b8aa0b05e4fa2d096","uuid":"8a63914a479e4028b1b992ee294feed4"}
                    LogUtil.e("xyd", result);
                    try {
                        Gson gson = new Gson();
                        ScanBean scanBean = gson.fromJson(result, ScanBean.class);
                        Intent intent = new Intent(mContext, ScanInputActivity.class);
                        intent.putExtra("scanBean", scanBean);
                        mContext.startActivity(intent);
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }

                    //Toast.makeText(this, "解析结果:" + result, Toast.LENGTH_LONG).show();
                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    //Toast.makeText(MainActivity.this, "解析二维码失败", Toast.LENGTH_LONG).show();
                    ToastUtil.showToast("二维码解析失败");
                }
            }
        }

    }


    @Override
    public void OnBannerClick(int position) {

    }


    private void getHotelMessage(){
        DialogUtil.delDialog(mContext);
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("hotelUuid",SharePrefUtil.getString(mContext,ShareKeys.HomeHotelUuid));
        service.getHotelQrCodeInfo(JsonUtils.convertParam("getHotelQrCodeInfo", h1)).enqueue(new CallbackImpl<HotelQrCodeInfoBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<HotelQrCodeInfoBean>> call, Response<HttpResult<HotelQrCodeInfoBean>> response) {

                DialogUtil.dismissLoadingDialog(mContext);
            }

            @Override
            public void onFailure(Call<HttpResult<HotelQrCodeInfoBean>> call, Throwable t) {
                super.onFailure(call, t);
                DialogUtil.dismissLoadingDialog(mContext);
            }

        });

    }

}
